/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package genArchi.impl;

import genArchi.AbstractTask;
import genArchi.ComputeBox;
import genArchi.GenArchiPackage;
import genArchi.Root;

import java.util.Collection;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;

import org.eclipse.emf.common.util.EList;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.eclipse.emf.ecore.impl.EObjectImpl;

import org.eclipse.emf.ecore.util.EObjectContainmentWithInverseEList;
import org.eclipse.emf.ecore.util.EObjectWithInverseResolvingEList;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.emf.ecore.util.InternalEList;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Compute Box</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link genArchi.impl.ComputeBoxImpl#getRoot <em>Root</em>}</li>
 *   <li>{@link genArchi.impl.ComputeBoxImpl#getNext <em>Next</em>}</li>
 *   <li>{@link genArchi.impl.ComputeBoxImpl#getPrevious <em>Previous</em>}</li>
 *   <li>{@link genArchi.impl.ComputeBoxImpl#isTodo <em>Todo</em>}</li>
 *   <li>{@link genArchi.impl.ComputeBoxImpl#getTasks <em>Tasks</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public abstract class ComputeBoxImpl extends EObjectImpl implements ComputeBox {
	/**
	 * The cached value of the '{@link #getNext() <em>Next</em>}' reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getNext()
	 * @generated
	 * @ordered
	 */
	protected EList<ComputeBox> next;

	/**
	 * The cached value of the '{@link #getPrevious() <em>Previous</em>}' reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getPrevious()
	 * @generated
	 * @ordered
	 */
	protected EList<ComputeBox> previous;

	/**
	 * The default value of the '{@link #isTodo() <em>Todo</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #isTodo()
	 * @generated NOT
	 * @ordered
	 */
	protected static final boolean TODO_EDEFAULT = true;

	/**
	 * The cached value of the '{@link #isTodo() <em>Todo</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #isTodo()
	 * @generated
	 * @ordered
	 */
	protected boolean todo = TODO_EDEFAULT;

	/**
	 * The cached value of the '{@link #getTasks() <em>Tasks</em>}' containment reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getTasks()
	 * @generated
	 * @ordered
	 */
	protected EList<AbstractTask> tasks;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected ComputeBoxImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return GenArchiPackage.Literals.COMPUTE_BOX;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Root getRoot() {
		if (eContainerFeatureID != GenArchiPackage.COMPUTE_BOX__ROOT) return null;
		return (Root)eContainer();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain basicSetRoot(Root newRoot, NotificationChain msgs) {
		msgs = eBasicSetContainer((InternalEObject)newRoot, GenArchiPackage.COMPUTE_BOX__ROOT, msgs);
		return msgs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setRoot(Root newRoot) {
		if (newRoot != eInternalContainer() || (eContainerFeatureID != GenArchiPackage.COMPUTE_BOX__ROOT && newRoot != null)) {
			if (EcoreUtil.isAncestor(this, newRoot))
				throw new IllegalArgumentException("Recursive containment not allowed for " + toString());
			NotificationChain msgs = null;
			if (eInternalContainer() != null)
				msgs = eBasicRemoveFromContainer(msgs);
			if (newRoot != null)
				msgs = ((InternalEObject)newRoot).eInverseAdd(this, GenArchiPackage.ROOT__COMPUTE_BOXES, Root.class, msgs);
			msgs = basicSetRoot(newRoot, msgs);
			if (msgs != null) msgs.dispatch();
		}
		else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, GenArchiPackage.COMPUTE_BOX__ROOT, newRoot, newRoot));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<ComputeBox> getNext() {
		if (next == null) {
			next = new EObjectWithInverseResolvingEList.ManyInverse<ComputeBox>(ComputeBox.class, this, GenArchiPackage.COMPUTE_BOX__NEXT, GenArchiPackage.COMPUTE_BOX__PREVIOUS);
		}
		return next;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<ComputeBox> getPrevious() {
		if (previous == null) {
			previous = new EObjectWithInverseResolvingEList.ManyInverse<ComputeBox>(ComputeBox.class, this, GenArchiPackage.COMPUTE_BOX__PREVIOUS, GenArchiPackage.COMPUTE_BOX__NEXT);
		}
		return previous;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public boolean isTodo() {
		return todo;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setTodo(boolean newTodo) {
		boolean oldTodo = todo;
		todo = newTodo;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, GenArchiPackage.COMPUTE_BOX__TODO, oldTodo, todo));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<AbstractTask> getTasks() {
		if (tasks == null) {
			tasks = new EObjectContainmentWithInverseEList<AbstractTask>(AbstractTask.class, this, GenArchiPackage.COMPUTE_BOX__TASKS, GenArchiPackage.ABSTRACT_TASK__COMPUTE_BOX);
		}
		return tasks;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void compute() {
		// TODO: implement this method
		// Ensure that you remove @generated or mark it @generated NOT
		throw new UnsupportedOperationException();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@SuppressWarnings("unchecked")
	@Override
	public NotificationChain eInverseAdd(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case GenArchiPackage.COMPUTE_BOX__ROOT:
				if (eInternalContainer() != null)
					msgs = eBasicRemoveFromContainer(msgs);
				return basicSetRoot((Root)otherEnd, msgs);
			case GenArchiPackage.COMPUTE_BOX__NEXT:
				return ((InternalEList<InternalEObject>)(InternalEList<?>)getNext()).basicAdd(otherEnd, msgs);
			case GenArchiPackage.COMPUTE_BOX__PREVIOUS:
				return ((InternalEList<InternalEObject>)(InternalEList<?>)getPrevious()).basicAdd(otherEnd, msgs);
			case GenArchiPackage.COMPUTE_BOX__TASKS:
				return ((InternalEList<InternalEObject>)(InternalEList<?>)getTasks()).basicAdd(otherEnd, msgs);
		}
		return super.eInverseAdd(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case GenArchiPackage.COMPUTE_BOX__ROOT:
				return basicSetRoot(null, msgs);
			case GenArchiPackage.COMPUTE_BOX__NEXT:
				return ((InternalEList<?>)getNext()).basicRemove(otherEnd, msgs);
			case GenArchiPackage.COMPUTE_BOX__PREVIOUS:
				return ((InternalEList<?>)getPrevious()).basicRemove(otherEnd, msgs);
			case GenArchiPackage.COMPUTE_BOX__TASKS:
				return ((InternalEList<?>)getTasks()).basicRemove(otherEnd, msgs);
		}
		return super.eInverseRemove(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eBasicRemoveFromContainerFeature(NotificationChain msgs) {
		switch (eContainerFeatureID) {
			case GenArchiPackage.COMPUTE_BOX__ROOT:
				return eInternalContainer().eInverseRemove(this, GenArchiPackage.ROOT__COMPUTE_BOXES, Root.class, msgs);
		}
		return super.eBasicRemoveFromContainerFeature(msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case GenArchiPackage.COMPUTE_BOX__ROOT:
				return getRoot();
			case GenArchiPackage.COMPUTE_BOX__NEXT:
				return getNext();
			case GenArchiPackage.COMPUTE_BOX__PREVIOUS:
				return getPrevious();
			case GenArchiPackage.COMPUTE_BOX__TODO:
				return isTodo() ? Boolean.TRUE : Boolean.FALSE;
			case GenArchiPackage.COMPUTE_BOX__TASKS:
				return getTasks();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@SuppressWarnings("unchecked")
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case GenArchiPackage.COMPUTE_BOX__ROOT:
				setRoot((Root)newValue);
				return;
			case GenArchiPackage.COMPUTE_BOX__NEXT:
				getNext().clear();
				getNext().addAll((Collection<? extends ComputeBox>)newValue);
				return;
			case GenArchiPackage.COMPUTE_BOX__PREVIOUS:
				getPrevious().clear();
				getPrevious().addAll((Collection<? extends ComputeBox>)newValue);
				return;
			case GenArchiPackage.COMPUTE_BOX__TODO:
				setTodo(((Boolean)newValue).booleanValue());
				return;
			case GenArchiPackage.COMPUTE_BOX__TASKS:
				getTasks().clear();
				getTasks().addAll((Collection<? extends AbstractTask>)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case GenArchiPackage.COMPUTE_BOX__ROOT:
				setRoot((Root)null);
				return;
			case GenArchiPackage.COMPUTE_BOX__NEXT:
				getNext().clear();
				return;
			case GenArchiPackage.COMPUTE_BOX__PREVIOUS:
				getPrevious().clear();
				return;
			case GenArchiPackage.COMPUTE_BOX__TODO:
				setTodo(TODO_EDEFAULT);
				return;
			case GenArchiPackage.COMPUTE_BOX__TASKS:
				getTasks().clear();
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case GenArchiPackage.COMPUTE_BOX__ROOT:
				return getRoot() != null;
			case GenArchiPackage.COMPUTE_BOX__NEXT:
				return next != null && !next.isEmpty();
			case GenArchiPackage.COMPUTE_BOX__PREVIOUS:
				return previous != null && !previous.isEmpty();
			case GenArchiPackage.COMPUTE_BOX__TODO:
				return todo != TODO_EDEFAULT;
			case GenArchiPackage.COMPUTE_BOX__TASKS:
				return tasks != null && !tasks.isEmpty();
		}
		return super.eIsSet(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public String toString() {
		if (eIsProxy()) return super.toString();

		StringBuffer result = new StringBuffer(super.toString());
		result.append(" (todo: ");
		result.append(todo);
		result.append(')');
		return result.toString();
	}

} //ComputeBoxImpl
